package com.example.demo.leetcode;

public class Leetcode345 {


    public String reverseVowels(String s) {
        char[] arr = s.toCharArray();
        int i = 0;
        int j = arr.length - 1;
        //"leetcode"
        while (i < j) {
            if (isYuanYin(arr[i]) && !isYuanYin(arr[j])) {
                j--;
            } else if (isYuanYin(arr[j]) && !isYuanYin(arr[i])) {
                i++;
            } else if (isYuanYin(arr[i]) && isYuanYin(arr[j])) {
                // 都是元音
                char temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
                i++;
                j--;
            } else {
                // 都不是元音
                i++;
                j--;
            }

        }
        return new String(arr);
    }

    public boolean isYuanYin(char c) {
        return "aoeiuAOEIU".indexOf(c) != -1;
    }

    public static void main(String[] args) {
        System.out.println(new Leetcode345().reverseVowels("leetcode"));
    }
}
